package org.abc.fund.repository.funds;

import org.abc.fund.entity.funds.FundMfDailyProfit;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Optional;

/**
 * Repository for FundMfDailyProfit entity.
 */
@Repository
public interface FundMfDailyProfitRepository extends JpaRepository<FundMfDailyProfit, Long> {
    /**
     * 根据基金代码和截止日期查找货币基金收益记录
     */
    Optional<FundMfDailyProfit> findByFundCodeAndEndDate(String fundCode, LocalDate endDate);
    
    /**
     * 根据基金代码查找最新的货币基金收益记录（按截止日期降序）
     */
    Optional<FundMfDailyProfit> findTopByFundCodeOrderByEndDateDesc(String fundCode);

    @Modifying
    @Transactional
    void deleteByFundCodeAndEndDateBetween(String fundCode, LocalDate startDate, LocalDate endDate);
}

